package com.da.javatest.niuke.other;

import java.util.HashMap;
import java.util.Map;

/**
 * @author JokerDa.
 * @date 2021/12/17 16:38
 * Description:https://www.nowcoder.com/practice/5d3d74c3bf7f4e368e03096bb8857871?
 * tpId=188&&tqId=38592&rp=1&ru=/activity/oj&qru=/ta/job-code-high-week/question-ranking
 */
public class NC156Solution {
    public int foundOnceNumber(int[] arr, int k) {
        if (k == 1) {
            return arr[0];
        }
        Map<Integer, Integer> map = new HashMap<>();
        for (int i : arr) {
            map.merge(i, 1, Integer::sum);
        }

        for (Integer i : map.keySet()) {
            if (map.get(i) == 1) {
                return i;
            }
        }
        return 0;
    }

    public static void main(String[] args) {
        NC156Solution test = new NC156Solution();
        System.out.println(test.foundOnceNumber(new int[] {5, 4, 1, 1, 5, 1, 5}, 3));
    }
}
